package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type HttpData struct {
	Flag int    `json:"flag"`
	Msg  string `json:"msg"`
}

func HelloWorld(w http.ResponseWriter,r *http.Request){
	req,err:= ioutil.ReadAll(r.Body)
	if err!=nil{
		fmt.Println("fail",err)
		return
	}
	fmt.Printf("%s",req)
	var requestBody HttpData
	err=json.Unmarshal(req,&requestBody)
	if err!=nil{
		fmt.Println("数据err:",err)
	}

	respBody:= struct {
		Code int
		HttpData
	}{
		Code:200,
		HttpData:requestBody,
	}
	resp,err:= json.Marshal(respBody)
	if err!=nil{
		fmt.Fprintf(w,"失败")
	}
	fmt.Fprintf(w,string(resp))

}
//func main(){
//	http.HandleFunc("/hello",HelloWorld)
//	fmt.Println("listen on 8080")
//	http.ListenAndServe(":8080",nil)
//
//}

